// 排片--表现层
var express = require('express');
var router = express.Router();
const schedulesService = require("../service/schedulesService")//自行引对应service方法
// 增加seating数据
router.post('/addSeating', async function (req, res, next) {
  let { objData } = req.body
  objData = JSON.parse(objData);
  const data=await schedulesService.addSeating(objData)
  res.send(data)
});

//获取影厅对应座位
router.get('/getSeats', async function (req, res, next) {
  const data = await schedulesService.getSeatByTheaterId(req.query)
  res.send(data);
});
router.get('/getSeating', async function (req, res, next) {
 const data = await schedulesService.getSeating(req.query)
 res.send(data);
});

// 从数据库获取拍片列表
router.get('/getSchedules', async function (req, res, next) {
  const data = await schedulesService.getSchedules()
  res.send(data);
});

//使用ID查询对应集合数据
router.get('/getById', async function (req, res, next) {
  const { listname, _id } = req.query
    var obj={};
    obj[listname] = _id;
  const data = await schedulesService.getById(obj)
  res.send(data);
});
// 从数据库删除指定ID数据
router.delete('/:_id', async function (req, res, next) {
  const { _id } = req.params
  const data = await schedulesService.deleteSchedules({ _id })
  res.send(data);

});
//更新数据库
router.patch('/:_id', async function (req, res, next) {
  const { _id } = req.params;
  const { movieId, cinemasId, theaterId, showTime, price } = req.body
  const result = await schedulesService.updata(_id, { movieId, cinemasId, theaterId, showTime, price })
  res.send(result)
});
//更新数据库
router.post('/addschedules', async function (req, res, next) {
  let { objData } = req.body
  var { movieId, cinemasId, theaterId, showTime, price } = JSON.parse(objData);
  price = ~~price
  let data = await schedulesService.addData({ movieId, cinemasId, theaterId, showTime, price })
  res.send(data);
});
router.get('/getmovies', async function (req, res, next) {
  const data = await schedulesService.getMovies()
  res.send(data);
});
router.get('/getcinems', async function (req, res, next) {
  const data = await schedulesService.getCinems()
  res.send(data);
});
router.get('/gettheaters', async function (req, res, next) {
  const { _id } = req.query
  const result = await schedulesService.getTheaters(_id)
  res.send(result);
});
module.exports = router;